package cn.edu.scau.dao;

import cn.edu.scau.entity.NursingPlan;
import cn.edu.scau.entity.NursingPlanShow;

import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@Mapper
@CacheNamespace
public interface NursingPlanMapper {
    @Delete({
        "delete from nursingplan",
        "where customerID = #{customerid,jdbcType=INTEGER}",
          "and nursingContentID = #{nursingcontentid,jdbcType=INTEGER}",
          "and nursingLevelID = #{nursinglevelid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(@Param("customerid") Integer customerid, @Param("nursingcontentid") Integer nursingcontentid, @Param("nursinglevelid") Integer nursinglevelid);

    @Insert({
        "insert into nursingplan (customerID, nursingContentID, ",
        "nursingLevelID, nursingPlanPeriod, ",
        "nursingPlanFrequency)",
        "values (#{customerid,jdbcType=INTEGER}, #{nursingcontentid,jdbcType=INTEGER}, ",
        "#{nursinglevelid,jdbcType=INTEGER}, #{nursingplanperiod,jdbcType=VARCHAR}, ",
        "#{nursingplanfrequency,jdbcType=INTEGER})"
    })
    int insert(NursingPlan record);

    @InsertProvider(type=NursingPlanSqlProvider.class, method="insertSelective")
    int insertSelective(NursingPlan record);

    @Select({
        "select",
        "customerID, nursingContentID, nursingLevelID, nursingPlanPeriod, nursingPlanFrequency",
        "from nursingplan",
        "where customerID = #{customerid,jdbcType=INTEGER}",
          "and nursingContentID = #{nursingcontentid,jdbcType=INTEGER}",
          "and nursingLevelID = #{nursinglevelid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="nursingContentID", property="nursingcontentid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="nursingLevelID", property="nursinglevelid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="nursingPlanPeriod", property="nursingplanperiod", jdbcType=JdbcType.VARCHAR),
        @Result(column="nursingPlanFrequency", property="nursingplanfrequency", jdbcType=JdbcType.INTEGER)
    })
    NursingPlan selectByPrimaryKey(@Param("customerid") Integer customerid, @Param("nursingcontentid") Integer nursingcontentid, @Param("nursinglevelid") Integer nursinglevelid);

	/**
	  * 连接查询护理计划的信息
	 * @return
	 */
	@Select({ 
		"select", 
		"nursingplan.customerID, customerName,nursingplan.nursingContentID,nursingContentProjectName, nursingplan.nursingLevelID, nursingLevelLevel,nursingPlanPeriod, nursingPlanFrequency", 
		"from ((nursingplan left join customer on nursingplan.customerID=customer.customerID) left join nursingcontent on  nursingplan.nursingContentID=nursingcontent.nursingContentID )left join nursinglevel on nursingplan.nursingLevelID=nursinglevel.nursingLevelID"})
	List<NursingPlanShow> selectAll();
    
    @UpdateProvider(type=NursingPlanSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(NursingPlan record);

    @Update({
        "update nursingplan",
        "set nursingPlanPeriod = #{nursingplanperiod,jdbcType=VARCHAR},",
          "nursingPlanFrequency = #{nursingplanfrequency,jdbcType=INTEGER}",
        "where customerID = #{customerid,jdbcType=INTEGER}",
          "and nursingContentID = #{nursingcontentid,jdbcType=INTEGER}",
          "and nursingLevelID = #{nursinglevelid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(NursingPlan record);
}